
var form_onBeforeLoad = function(param)
{
	jQuery(this).datagrid('options').url;
};

function grid_preinit()
{
	
}

function __AB_PDoremi_EmailManager_BuildUrl(){
	var options=jQuery("#test_grid").datagrid("options");
	var url=link_url;
	var search_email=jQuery.trim(jQuery("#tb_search_sku").searchbox("getValue"));
	if(search_email!="")
		{
		url+="&search_email="+search_email;
	}
	var type_email = $('#cc').combobox('getValue');
	if(type_email!="")
		{
		url+="&type_email="+type_email;
	}
	// for pager
	url+="&page="+options.pageNumber+"&pageSize="+options.pageSize;
	return url;

}
/**
* This function init the Easy Jquery UI
* For the Tree Grid in page Categories Manager
* @author: trungdt
* @since: Sep 27, 2011 
*/
function __AB_PDoremi_EmailManager_Init(link_url, menu_selector){

	// use data grid, not tree grid
	$('#cc').combobox({
		valueField:'id',
		textField:'text'
	});
	$('#test_grid').datagrid({
		url: link_url,
		idField: 'id',
		columns:[[
		{field:'email',title:'Email',width:200},
		{field:'subject',title:'Subject',width:100},
		{field:'content',title:'Content',width:200},
		{field:'status',title:'Status',width:60},
		{field:'sender',title:'Sender',width:60},
		{field:'mail_log',title:'Mail log',width:100},
		{field:'is_error',title:'Lỗi',formatter:function(value){
				if(value==1)
					{
					return 'Error';
				}
				else
					{
					return 'None';
				}
			},width:60}

		]],
		onBeforeLoad: function(row,param){
			jQuery("#test_grid").datagrid("options").url=__AB_PDoremi_EmailManager_BuildUrl();    
		},
		onContextMenu: function(e,row){
			e.preventDefault();
			$(this).datagrid('unselectAll');
			$(this).datagrid('select', row.id);
			$('#'+menu_selector).menu('show', {
				left: e.pageX,
				top: e.pageY,
			});
		},
	});
} 
{ 

	var node = $('#'+table_selector).datagrid('getSelected');
	if (node)
		{
		if(type==1)
			{
			var msg = "Bạn có chắc muốn blacklist email này không?";
		}
		else
			{
			var msg = "Bạn có chắc muốn unblacklist email này không?";
		}
		if (!confirm(msg))
			return;
		$.post("/index.php",
		{
			module: 'mailinglistmodule',
			action: 'blacklist',
			ajax_action: '1',
			id: node.id
		}, 
		function(data)
		{
			jQuery('#EmailManager').datagrid('reload');
		}
		);
	}
} 
